feat(mac-crafter): retry code-signing attempts
authorJyrki Gadinger <nilsding@nilsding.org>
Thu, 15 May 2025 14:11:38 +0000 (16:11 +0200)
committerJyrki Gadinger <nilsding@nilsding.org>
Fri, 30 May 2025 07:54:41 +0000 (09:54 +0200)
This step sometimes fails with an error such as: "A timestamp was
expected but was not found.".  Any code-signing errors will result in
the notarisation step to fail.

Apparently this might be due to intermittent network issues.  Let's just
retry codesigning a couple of times in the case it fails ...

See also: https://developer.apple.com/documentation/security/resolving-common-notarization-issues#Include-a-secure-timestamp

Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
admin/osx/mac-crafter/Sources/Utils/Codesign.swift

index 1f43d3e49aed7da9b226b4eecc3a372622eaeac9..92713313344007d2d62aa574da0ff4a658386641 100644 (file)
@@ -55,9 +55,17 @@ func isExecutable(_ path: String) throws -> Bool {
 func codesign(identity: String, path: String, options: String = defaultCodesignOptions) throws {
     print("Code-signing \(path)...")
     let command = "codesign -s \"\(identity)\" \(options) \"\(path)\""
-    guard shell(command) == 0 else {
-        throw CodeSigningError.failedToCodeSign("Failed to code-sign \(path).")
+    for _ in 1...5 {
+        guard shell(command) == 0 else {
+            print("Code-signing failed, retrying ...")
+            continue
+        }
+
+        // code signing was successful
+        return
     }
+
+    throw CodeSigningError.failedToCodeSign("Failed to code-sign \(path).")
 }
 
 func recursivelyCodesign(